<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell @click="cellClickFn">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ item.title }}</span>
          <!-- 单图 -->
          <img
            class="thumb"
            v-lazy="item.cover.images[0]"
            v-if="item.cover.type === 1"
          />
        </div>
        <!-- 三图容器 -->
        <div class="thumb-box" v-if="item.cover.type > 1">
          <!-- urlStr: 图片地址字符串 -->
          <img
            class="thumb"
            v-for="(urlStr, index) in item.cover.images"
            :key="index"
            v-lazy="urlStr"
            alt=""
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ item.aut_name }} &nbsp;&nbsp;</span>
            <span>{{ item.comm_count }}评论&nbsp;&nbsp;</span>
            <span>{{ item.pubdate }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="crossFn" v-if="closeShow" />
        </div>
      </template>
    </van-cell>

    <!-- 底部反馈面板 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      :cancel-text="cancelText"
      get-container="body"
    />
    <!-- <van-action-sheet v-model="!show" :actions="actions" @select="onSelect"  :cancel-text="cancelText"
    get-container="body"/> -->
  </div>
</template>

<script>
import { firstActions, secondActions } from '@/api/reports'
export default {
  data () {
    return {
      show: false, // 底部反馈面板是否显示
      actions: firstActions,
      cancelText: '取消'
    }
  },
  methods: {
    // 点击选项触发
    onSelect (action, index) {
      console.log(action)
      // action: { name: '反馈垃圾内容' }
      // action: { name: '标题夸张', value: 1}
      if (action.name === '反馈垃圾内容') {
        console.log('准备切换数据源')
        this.actions = secondActions
      } else if (action.name === '不感兴趣') {
        this.$emit('removeE', this.item, action) // 把文章对象传递给父亲(要删除)
      } else if (action.name === '拉黑作者') {
        //
      } else if (action.name === '返回') {
        // 二级面板, 点击返回, 切换数据源
        this.actions = firstActions
      } else {
        // 只要进到这里的都是二级面板反馈选项
        this.$emit('removeE', this.item, action)
      }
    },
    // 取消点击事件 - 把反馈数据拿回来
    cancelFn () {
      // this.cancelText = '取消'
      this.actions = firstActions
      // this.show = true
    },
    // 反馈按钮点击
    crossFn () {
      this.show = true // 反馈面板出现
    },
    // 跳转文章详情
    cellClickFn () {
      this.$router.push({
        path: `/article?aid=${this.item.art_id}`
        /*
        // 你可以用下面交给push方法让它拼接, 或者你自己拼接(都ok)
        path: '/article',
        query: {
          aid: this.item.art_id
        }
        */
      })
    }
  },
  props: {
    item: {
      // 文章对象
      type: Object,
      default () {
        return {}
      }
    },
    // 控制右下角x是否显示(默认显示)
    closeShow: {
      type: Boolean,
      default: true // 简单类型直接写默认值,复杂类型写函数+return形式(固定语法)
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
